package com.hiscene.structurestream

import org.apache.hadoop.hbase.client.{Connection, ConnectionFactory}
import org.apache.hadoop.hbase.HBaseConfiguration
import org.apache.hadoop.hbase.security.User
import org.apache.hadoop.security.UserGroupInformation

object HbaseConnectionPool {


  private var conn: Connection = _

  def getConnection: Connection = {
    if (conn == null) {
      this.synchronized {
        if (conn == null) {
          createHbaseConnection()
        }
      }
    }
    conn
  }

  private def createHbaseConnection():Unit={

    val hbaseConf = HBaseConfiguration.create()
    hbaseConf.set("hbase.zookeeper.quorum", "192.168.1.16,192.168.1.17,192.168.1.18")
    hbaseConf.set("hbase.zookeeper.property.clientPort", "2181")
    hbaseConf.set("zookeeper.znode.parent", "/hbase-unsecure")
    val userGroupInformation: UserGroupInformation = UserGroupInformation.createRemoteUser("hbase")
    conn = ConnectionFactory.createConnection(hbaseConf,User.create(userGroupInformation))

  }
}
